<?php
//配置跨域请求头部
header('Access-Control-Allow-Origin:*');

header('Access-Control-Allow-Methods:POST');

header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, x-file-name");

//是否有ajax 异步请求的(post) 发送过来
if($_POST)
{
    //接收数据
    $username = isset($_POST['username']) ? $_POST['username'] : '';
    $password = isset($_POST['password']) ? $_POST['password'] : '';

    //组装一个返回结果
    $result = [
        'result' => true, //登录成功
        'msg' => '登录成功', //返回提醒
        'code' => '1001', //成功登录的状态码
    ];

    //将数据转换成json类型的
    $json = json_encode($result);

    //延迟属性 单位：s秒
    sleep(10);

    //将转换完的json数据返回给前端
    echo $json;
    exit;
}

?>